#include "sys.h"
#include "timer.h"

TIM_HandleTypeDef TIM3_Handler; 
TIM_OC_InitTypeDef TIM3_CH2Handler;

void TIM_CH2init(u16 arr,u16 psc)
{
TIM3_Handler.Instance=TIM3; 
TIM3_Handler.Init.Prescaler=psc;
TIM3_Handler.Init.CounterMode=TIM_COUNTERMODE_UP;
TIM3_Handler.Init.Period=arr;
TIM3_Handler.Init.ClockDivision=TIM_CLOCKDIVISION_DIV1;
	HAL_TIM_PWM_Init(&TIM3_Handler);
	TIM3_CH2Handler.OCMode=TIM_OCMODE_PWM1; 
	TIM3_CH2Handler.Pulse=arr*0.01; 
	TIM3_CH2Handler.OCPolarity=TIM_OCPOLARITY_LOW;
	HAL_TIM_PWM_ConfigChannel(&TIM3_Handler,&TIM3_CH2Handler,TIM_CHANNEL_2);
	HAL_TIM_PWM_Start(&TIM3_Handler,TIM_CHANNEL_2);
}


void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *htim)
{
 if(htim->Instance==TIM3)
{
__HAL_RCC_TIM3_CLK_ENABLE(); 
HAL_NVIC_SetPriority(TIM3_IRQn,1,3);
HAL_NVIC_EnableIRQ(TIM3_IRQn); 
}
}
void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef *htim)
{
GPIO_InitTypeDef GPIO_Initure;
 if(htim->Instance==TIM3)
{
__HAL_RCC_TIM3_CLK_ENABLE(); 
__HAL_AFIO_REMAP_TIM3_PARTIAL(); 
__HAL_RCC_GPIOB_CLK_ENABLE(); 
GPIO_Initure.Pin=GPIO_PIN_5; 
GPIO_Initure.Mode=GPIO_MODE_AF_PP; 
GPIO_Initure.Pull=GPIO_PULLUP;
GPIO_Initure.Speed=GPIO_SPEED_FREQ_HIGH;
	HAL_GPIO_Init(GPIOB,&GPIO_Initure);
}
}
void TIM_SetTIM3Compare2(u32 compare2)
{
TIM3->CCR2=compare2;
};

